#include "AC33Mxxx_conf.h"
#include "driver_header.h"


UINT32 	g_systick_count; 
UINT32	g_wdt_count; 

#if 1

UINT32	g_SPI0_count; 
UINT32	g_SPI1_count; 

#endif

UINT32	g_UART0_count; 
UINT32	g_UART1_count; 


UINT32	g_POARTA_count; 
UINT32	g_POARTB_count; 
UINT32	g_POARTD_count; 


void NMI_Handler (void)
{
	while(1); 
}


void HardFault_Handler (void)
{
	while(1); 
}

extern int g_systick_request;
extern int g_sec;
extern int g_msec;
extern int g_min;
extern int g_hour;
extern int g_day;
extern int g_mon;
extern int g_year;

void SysTick_Handler1 (void)		//void SysTick_Handler (void)
{
/*
	volatile UINT32 		reg_val;

	reg_val = CSP_SYSTICK_GET_CVR(SYSTICK); 

	#if 0
	if (++g_systick_count & 0x0001)
		HAL_MONITOR_OUTPUT_HIGH(); 
	else
		HAL_MONITOR_OUTPUT_LOW(); 
	#endif
*/	
	g_systick_request = 1;
	
	g_msec += 2;
	
	if( g_msec == 1000 )
	{
		g_msec = 0;
		g_sec ++;
		if( g_sec == 60 )
		{
			g_min ++;
			g_sec = 0;
			if( g_min == 60 )
			{
				g_hour ++;
				g_min = 0;
				if( g_hour == 24 )
				{
					g_day ++;
					g_hour = 0;
					if( g_day == 30 )
					{
						g_mon ++;
						g_day= 0;
						if( g_mon == 12 )
						{
							g_year ++;
							g_hour = 0;
			     }
				 }
				}	
			}
		}
	}

}
//########################################################################
//########################################################################
//########################################################################




/**
***********************************************************************************************
* @ Name : WDT_Handler 
*
* @ IRQ 
*		IRQ_WDT (3)
*
***********************************************************************************************
*/

void WDT_Handler (void)
{

	CSP_WDT_SET_WDTLR(WDT, 500000); 


	#if 0
	if (++g_wdt_count & 0x0001)
		HAL_MONITOR_OUTPUT_HIGH(); 
	else
		HAL_MONITOR_OUTPUT_LOW(); 
	#endif


}


/**
***********************************************************************************************
* @ Name : GPIOA_Handler 
*
* @ IRQ 
*		IRQ_GPIOA (15)
*
***********************************************************************************************
*/
void GPIOAO_Handler(void)
{
	CSP_PCU_T	* pcu = PCU_A; 
	UINT32	 	reg_val; 
	
	if (g_POARTA_count & 0x01) 
		CSP_GPIO_OutputHigh(GPIO_D,PIN_8);
	else
		CSP_GPIO_OutputLow(GPIO_D,PIN_8);
	g_POARTA_count++;
	
	reg_val = CSP_PCU_GET_PnISR(pcu); 
	CSP_PCU_SET_PnISR(pcu, reg_val); 
	
}


/**
***********************************************************************************************
* @ Name : GPIOB_Handler 
*
* @ IRQ 
*		IRQ_GPIOB (16)
*
***********************************************************************************************
*/
void GPIOBO_Handler(void)
{
	CSP_PCU_T	* pcu = PCU_B; 
	UINT32	 	reg_val; 

	if (g_POARTB_count & 0x01) 
		CSP_GPIO_OutputHigh(GPIO_D,PIN_9);
	else
		CSP_GPIO_OutputLow(GPIO_D,PIN_9);
	g_POARTB_count++;

	reg_val = CSP_PCU_GET_PnISR(pcu); 
	CSP_PCU_SET_PnISR(pcu, reg_val); 
	
}


#if 0
/**
***********************************************************************************************
* @ Name : GPIOC_Handler 
*
* @ IRQ 
*		IRQ_GPIOC (17)
*
***********************************************************************************************
*/
void GPIOC_Handler(void)
{
	CSP_PCU_T	* pcu = PCU_C; 
	UINT32	 	reg_val; 

	reg_val = CSP_PCU_GET_PnISR(pcu); 
	CSP_PCU_SET_PnISR(pcu, reg_val); 
	
}
#endif

/**
***********************************************************************************************
* @ Name : GPIOD_Handler 
*
* @ IRQ 
*		IRQ_GPIOD (18)
*
***********************************************************************************************
*/

void GPIODO_Handler(void)
{
	CSP_PCU_T	* pcu = PCU_D; 
	UINT32	 	reg_val; 

	if (g_POARTD_count & 0x01) 
		CSP_GPIO_OutputHigh(GPIO_D,PIN_14);
	else
		CSP_GPIO_OutputLow(GPIO_D,PIN_14);
	g_POARTD_count++;

	reg_val = CSP_PCU_GET_PnISR(pcu); 
	CSP_PCU_SET_PnISR(pcu, reg_val); 
	
}



/**
***********************************************************************************************
* @ Name : UART0_Handler 
*
* @ IRQ 
*		IRQ_UART0 (22)
*
***********************************************************************************************
*/
void UART0_Handler(void)
{
	//UART0_Transmit_Receive_ISR(); 

	g_UART0_count++; 
}

#if 1

/**
***********************************************************************************************
* @ Name : UART1_Handler 
*
* @ IRQ 
*		IRQ_UART1 (23)
*
***********************************************************************************************
*/
void UART1_Handler(void)
{
	
	//UART1_Transmit_Receive_ISR(); 

	g_UART1_count++; 
	
}


#endif


#if 1

/**
***********************************************************************************************
* @ Name : SPI0_Handler 
*
* @ IRQ 
*		IRQ_SPI0 (26)
*
***********************************************************************************************
*/
void SPI0_Handler(void)
{

	//HAL_MONITOR_OUTPUT_HIGH(); 


	//SPI0_Master_Transmit_Receive_ISR(); 
	//SPI0_Slave_Transmit_Receive_ISR(); 

	g_SPI0_count++; 

	//HAL_MONITOR_OUTPUT_LOW(); 
}

/**
***********************************************************************************************
* @ Name : SPI1_Handler 
*
* @ IRQ 
*		IRQ_SPI1 (27)
*
***********************************************************************************************
*/
void SPI1_Handler(void)
{

	//HAL_MONITOR_OUTPUT_HIGH(); 
	
	//SPI1_Master_Transmit_Receive_ISR();  
	//SPI1_Slave_Transmit_Receive_ISR();  

	g_SPI1_count++; 

	//HAL_MONITOR_OUTPUT_LOW(); 
}


#endif
